package com.yang.provider.service.impl;

import com.yang.provider.entity.User;
import com.yang.provider.manager.UserManager;
import com.yang.provider.service.UserService;
import com.yang.common.dto.ResultCodeEnum;
import com.yang.common.dto.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Objects;


@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserManager userManager;





    @Override
    public ResultVO<User> login(User user) {
        ResultVO<User> re = userManager.getUserByNameAndPassword(user.getLoginName(), user.getPassword());
        if (!re.isSuccess() || Objects.isNull(re.getResultData())){
            return ResultVO.error(ResultCodeEnum.LOGIN_ERROR);
        }
        return re;
    }

    @Override
    public ResultVO<User> logout(HttpServletRequest request) {
        HttpSession session = request.getSession();
        return ResultVO.success();
    }

}
